package com.xiaomaoguai.other.utils;

import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

/**
 * @Description :截图
 * @FileName: CaptureScreen.java
 * @Author :WeiHui.Zhang
 * @Data : 2015年6月11日 下午2:02:46
 * @Version:V1.00
 */
public class CaptureScreen {

	public static void captureScreen(String fileName) throws Exception {
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		Rectangle screenRectangle = new Rectangle(screenSize);
		Robot robot = new Robot();
		BufferedImage image = robot.createScreenCapture(screenRectangle);
		File imgFile = new File(fileName);
		ImageIO.write(image, "png", imgFile);
		if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN))
			Desktop.getDesktop().open(imgFile);
	}

	public static void main(String[] args) {
		try {
			captureScreen("F:\\Test22.jpg");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
